/*
// copilot 永远的神!!!
#include <iostream>
using namespace std;

int n;
int m;
int l, r;
int x;
int xu_hao;

void solve(int xuhao) {
	if (xuhao == 1) {
		cin >> x;
		int temp = (n >> x) & 1;
		cout << temp << endl;

	}
	if (xuhao == 2) {
		int ans = 0;
		cin >> l >> r;
		int i;
		for (i = 0; i <= r; ++i) {
			if (i < l) {
				int temp = n >> i & 1;
				if (temp == 1)
					ans = (1 << i) + ans;
			}
			else {
				int tmp = n >> i & 1;
				if (tmp == 0) {
					ans = (1 << i) + ans;
				}
			}
		}
		while (n >> i != 0) {
			int temp = n >> i & 1;
			if (temp == 1)
				ans = (1 << i) + ans;
			++i;
		}

		cout << ans << endl;
		n = ans;

	}
	if (xuhao == 3) {
		int ans = 0;
		cin >> l >> r;
		int i;
		for (i = 0; i <= r; ++i) {
			if (i < l) {
				int temp = n >> i & 1;
				if (temp == 1)
					ans = (1 << i) + ans;
			}
			else
				ans = (1 << i) + ans;
		}
		while (n >> i != 0) {
			int temp = n >> i & 1;
			if (temp == 1)
				ans = (1 << i) + ans;
			++i;
		}
		cout << ans << endl;
		n = ans;


	}
	if (xuhao == 4) {
		int ans = 0;
		cin >> l >> r;
		int i;
		for (i = 0; i <= r; ++i) {
			if (i < l) {
				int temp = n >> i & 1;
				if (temp == 1)
					ans = (1 << i) + ans;
			}
		}
		while (n >> i != 0) {
			int temp = n >> i & 1;
			if (temp == 1)
				ans = (1 << i) + ans;
			++i;
		}
		cout << ans << endl;
		n = ans;


	}
	if (xuhao == 5) {
		int temp = n;
		if (temp == 0) {
			cout << 0 << endl;
			return;
		}
		int ans = 0;
		while ((temp & 1) != 1) {
			temp = temp >> 1;
			ans++;
		}

		cout << (1 << ans) << endl;
	}
	return;
}

int main()
{
	cin >> n >> m;
	while (m--) {
		cin >> xu_hao;
		solve(xu_hao);
	}
	return 0;
}

*/

/*
 //打印n阶乘行,回溯
#include<iostream>
using namespace std;
bool st[10];
int path[10];
int n;
void dfs(int u) {
	if (u > n) {
		for (int i = 1; i <= n; ++i) {
			cout << path[i]<<" ";
		}
		cout << endl;
		return;
	}
		//3 2 1
		//3 1 2
		//2 3 1
		//2 1 3
		//1 3 2
		//1 2 3
	//for (int i = n; i >=1; --i) {
	//	if (st[i])
	//		continue;
	//	st[i] = true;
	//	path[u] = i;
	//	dfs(u + 1);
	//	st[i] = false;
	//}


		//1 2 3
		//1 3 2
		//2 1 3
		//2 3 1
		//3 1 2
		//3 2 1
	for (int i = 1; i <= n; ++i) {
		if (st[i])
			continue;
		st[i] = true;
		path[u] = i;
		dfs(u + 1);
		st[i] = false;
	}

}

int main() {

	cin >> n;
	dfs(1);
	return 0;
}
*/

/*
#include<iostream>

using namespace std;
int n, k;
string S, T;
const int N = 10;
int op[N], x[N], y[N];
int flag[N];

bool dfs(int cur_i) {
	flag[cur_i] = 1;
	if (op[cur_i] == 1) {
		S[x[cur_i]] = (S[x[cur_i]] + y[cur_i] - '0') % 10 + '0';
	}
	if (op[cur_i] == 2) {
		int temp = S[x[cur_i]];
		S[x[cur_i]] = S[y[cur_i]];
		S[y[cur_i]] = temp;
	}

	if (S == T)
		return true;

	for (int i = 1; i <= k; ++i) {
		if (flag[i] != 1) 
			if(dfs(i))
				return true;
	}
	flag[cur_i] = 0;

	return false;
}

int main()
{
	cin >> n >> S >> T >> k;
	for (int i = 1; i <= k; i++) 
		cin >> op[i] >> x[i] >> y[i];

	for (int i = 1; i <= k; ++i) {
		if (dfs(i)) {
			cout << "Yes" << endl;
			return 0;
		}
		
	}
	cout << "No" << endl;
	return 0;
}
*/


/*
#include<iostream>
#include<algorithm>
using namespace std;
int nums[3] = { 1,2,3 };
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < 3; ++i) {
		cout << nums[i] << " ";
	}
	cout << endl;
	while (next_permutation(nums, nums + 3)){
		for (int i = 0; i < 3; ++i) {
			cout << nums[i] << " ";
		}
		cout << endl;
	}
	return 0;
}
*/


#include<iostream>
#include<algorithm>
using namespace std;
int num[10] = { 1,2,3,4,5,6,7,8,9 };
int cnt;
int func(int a, int b)
{
	int sum = 0;
	for (int i = a; i <= b; i++)
	{
		sum = sum * 10 + num[i];
	}
	return sum;
}
int main()
{
	int n;
	cin >> n;
	// 手动验证初始排列
	for (int i = 0; i < 9; i++) {
		int a = func(0, i);
		for (int j = i + 1; j < 8; j++) {
			int b = func(i + 1, j);
			int c = func(j + 1, 8);
			if (n * c == a * c + b) {
				cnt++;
			}
		}
	}
	while (next_permutation(num, num + 9))
	{
		for (int i = 0; i < 9; i++)
		{
			int a = func(0, i);
			for (int j = i + 1; j < 9; j++)
			{
				int b = func(i + 1, j);
				int c = func(j + 1, 8);
				if (n * c == a * c + b)
				{
					cnt++;
				}
			}
		}
	}
	cout << cnt;
	return 0;
}
